<?php $percent = ceil((1/(count($this->ds_tennhom)+1))*100); ?>
<div class="row-fluid">
    <div id="content" class="row-fluid">
        <div class="box span12">
            <div class="box-header well">
                <h2>Bảng quy định quyền</h2>
            </div>
            
            <div class="box-content">
                <table class="table table-bordered table-striped">
                    <thead>
                        <tr class="line-table">
                            <th style="width: <?php echo $percent."%"?>;">
                                <div class="right">Nhóm</div><hr/>
                                <div>Nghiệp Vụ</div>
                            </th>
                            <?php foreach($this->ds_tennhom as $manhom=>$ten_nhom){ ?>
                            <th class="center" style="width: <?php echo $percent."%"?>;"><?php echo $ten_nhom;?></th>
                            <?php } ?>
                        </tr>
                    </thead>
                    
                    <tbody>
                        <?php foreach($this->datas as $manghiepvu=> $ds_phanquyen){ ?>
                        <tr>
                            <td><?php echo $this->ds_tennghiepvu[$manghiepvu];?></td>
                            <?php foreach($ds_phanquyen as $manhom=>$quyen){ ?>
                            <td class="center">
                            <?php if($quyen==1){ ?>
                            <a href="#" rel="1" json_datas="[<?php echo $manhom.",".$manghiepvu; ?>]" class="change-permistion"></a>
                            <?php }else{ ?>
                            <a href="#" rel="0" json_datas="[<?php echo $manhom.",".$manghiepvu; ?>]" class="change-permistion"></i></a>
                            <?php } ?>
                            </td>
                            <?php } ?>
                        </tr>
                        <?php } ?>
                    </tbody>
                </table>
            </div>
        </div>
    </div>	
</div>

<script>
$(function(){
    $("a.change-permistion").click(function(){
        var $this = $(this);
        var link = "<?php echo $this->url(array('controller'=>'system','action'=>'permission'))?>";
        var send_data = {'ajax':JSON.parse($(this).attr("json_datas"))};
        $.post(link,send_data,function(rdata){
            $this.attr("rel", ($this.attr("rel")==1)?0:1 );
        },'json')
        return false;
    });
});
</script>